package com.mark.springboot.service.impl;

import com.mark.springboot.entity.Category;
import com.mark.springboot.mapper.AdminMapper;
import com.mark.springboot.mapper.CategoryMapper;
import com.mark.springboot.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @Author: MARK
 * @Date: 2019/8/20 18:37
 * @Version: 1.0.0
 * @Description:
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public boolean del(Integer id) {
        categoryMapper.deleteByPrimaryKey(id);
        return true;
    }

    @Override
    public List<Category> selectAll() {
        List<Category> categories = categoryMapper.selectAll();
        return categories;
    }

    @Override
    public boolean add(Category category) {
        category.setCreateTime(LocalDate.now());
        category.setUpdateTime(LocalDate.now());
        categoryMapper.insert(category);
        return true;
    }

    @Override
    public boolean update(Category category) {
        category.setUpdateTime(LocalDate.now());
        categoryMapper.updateByPrimaryKeySelective(category);
        return true;
    }
}
